package com.lagou.service.impl;

import com.lagou.dao.CourseContentMapper;
import com.lagou.domain.Course;
import com.lagou.domain.CourseSection;
import com.lagou.service.CourseContextService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CourseContextServiceImpl implements CourseContextService {

    @Autowired
    private CourseContentMapper courseContentMapper;


    @Override
    public List<CourseSection> findSectionAndLessonByCourseId(Integer courseId) {

        List<CourseSection> list = courseContentMapper.findSectionAndLessonByCourseId (courseId);


        return list;
    }

    @Override
    public Course findCourseById(int courseId) {

        Course course = courseContentMapper.findCourseById (courseId);
        return course;
    }

    @Override
    public void saveSection(CourseSection courseSection) {

        //补全信息
        Date date = new Date ();
        courseSection.setCreateTime (date);
        courseSection.setUpdateTime (date);

        courseContentMapper.saveSection (courseSection);
    }

    @Override
    public void updateSection(CourseSection courseSection) {

        //补全信息
        courseSection.setUpdateTime (new Date ());

        courseContentMapper.updateSection (courseSection);
    }

    /*修改章节状态的方法*/
    @Override
    public void updateSectionStatus(int id, int status) {

        //封装数据
        CourseSection courseSection = new CourseSection ();
        courseSection.setId (id);
        courseSection.setStatus (status);
        courseSection.setUpdateTime (new Date ());

        courseContentMapper.updateSectionStatus (courseSection);
    }
}
